// pages/index/comps/cardAdv/cardAdv.js
const common = require('../../../../utils/util.js')
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        nowDate: String,
        isLogin: Boolean,
        isBind: Boolean
    },

    /**
     * 组件的初始数据
     */
    data: {
        currentIndex: 0,
        parentId: '',
        showBind: false
    },

    /**
     * 组件的方法列表
     */
    methods: {
        myCatchTouch: function () {
            return
        },

        parentIdInput: function (e) {
            this.setData({
                parentId: e.detail.value
            })
        },

        cancleBind: function () {
            this.setData({
                showBind: false,
                parentId: ''
            })
        },

        sureBind: function () {
            if (this.data.parentId == '') {
                wx.showToast({
                    title: '请填写邀请人ID',
                    icon: 'none',
                    duration: 2000
                })
                return
            }
            wx.showLoading({
                title: '请稍后'
            })
            let data = {
                belong_refer: this.data.parentId
            }
            common.post('User/set_belong_refer', data).then(function (res) {
                wx.hideLoading()
                if (res.code == 204) {
                    wx.showToast({
                        title: res.error,
                        icon: 'none',
                        duration: 2000
                    })
                    return
                }
                common.post('User/user_info', {}).then(function (res) {
                    if (res.code == 204) {
                        return
                    } else {
                        wx.setStorageSync("roleType", res.role_type)
                        wx.setStorageSync("storeId", res.store_id)
                        wx.setStorageSync("realStoreId", res.real_store_id)
                        wx.setStorageSync("userId", res.user_id)
                        wx.setStorageSync("parentId", res.parent_id)
                        wx.setStorageSync("userPhone", res.phone)
                        wx.reLaunch({
                            url: '/pages/index/index'
                        })
                    }
                }).catch(function (e) { })
            }).catch(function (e) { })
        },

        currentIndexChange: function (e) {
            this.setData({
                currentIndex: e.detail.current
            })
        },

        goLogin: function () {
            wx.setStorageSync('prePageUrl', '/pages/index/index')
            wx.redirectTo({
                url: '/pages/user/login/login'
            })
        },

        beMember: function () {
            wx.navigateTo({
                url: '/pages/beMember/beMember'
            })
        },

        goBind: function () {
            this.setData({
                showBind: true
            })
        }
    }
})